//
//  DKAuthBaseStepInfoCell.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/29.
//

#import "DKAuthBaseStepInfoCell.h"
#import "DKAuthBaseStepSubView.h"
static NSString * DKAuthBaseStepCellId = @"DKAuthBaseStepCellId";
@interface DKAuthBaseStepInfoCell()
@property (nonatomic, strong)DKAuthBaseStepSubView * dk_AuthBaseStepBasic;
@property (nonatomic, strong)DKAuthBaseStepSubView * dk_AuthBaseStepContact;
@property (nonatomic, strong)DKAuthBaseStepSubView * dk_AuthBaseStepBankCard;
@end
@implementation DKAuthBaseStepInfoCell
+ (instancetype)authBaseStepCell:(UITableView *)tableView{
    DKAuthBaseStepInfoCell * dk_AuthBaseStepCell = [tableView dequeueReusableCellWithIdentifier:DKAuthBaseStepCellId];
    if (!dk_AuthBaseStepCell) {
        dk_AuthBaseStepCell = [[DKAuthBaseStepInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DKAuthBaseStepCellId];
    }
    dk_AuthBaseStepCell.backgroundColor = [UIColor clearColor];
    dk_AuthBaseStepCell.selectionStyle = UITableViewCellSelectionStyleNone;
    dk_AuthBaseStepCell.accessoryType = UITableViewCellAccessoryNone;
    return dk_AuthBaseStepCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    CGFloat AuthBaseStepW = (DK_SCREEN_W - DK_IsWidthScale(105))/3;
    self.dk_AuthBaseStepBasic = [[DKAuthBaseStepSubView alloc] init];
    self.dk_AuthBaseStepBasic.authBaseStepType = AuthBaseStepTypeBasic;
    [self addSubview:self.dk_AuthBaseStepBasic];
    [self.dk_AuthBaseStepBasic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(26)));
        make.bottom.equalTo(@(DK_IsWidthScale(0)));
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.width.equalTo(@(AuthBaseStepW));
    }];
    UIImageView * dk_AuthBaseStepBasicCenterImgView = [[UIImageView alloc] init];
    dk_AuthBaseStepBasicCenterImgView.image = DK_GetImage(@"dk_AuthStepMiniNext");
    dk_AuthBaseStepBasicCenterImgView.userInteractionEnabled = YES;
    [self addSubview:dk_AuthBaseStepBasicCenterImgView];
    [dk_AuthBaseStepBasicCenterImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_AuthBaseStepBasic.mas_right).offset(DK_IsWidthScale(5));
        make.width.equalTo(@(DK_IsWidthScale(12)));
        make.height.equalTo(@(DK_IsWidthScale(12)));
        make.top.equalTo(self.dk_AuthBaseStepBasic).offset(DK_IsWidthScale(30));
    }];
    self.dk_AuthBaseStepContact = [[DKAuthBaseStepSubView alloc] init];
    self.dk_AuthBaseStepContact.authBaseStepType = AuthBaseStepTypeContact;
    [self addSubview:self.dk_AuthBaseStepContact];
    [self.dk_AuthBaseStepContact mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dk_AuthBaseStepBasic);
        make.bottom.equalTo(@(DK_IsWidthScale(0)));
        make.left.equalTo(dk_AuthBaseStepBasicCenterImgView.mas_right).offset(DK_IsWidthScale(4));
        make.width.equalTo(@(AuthBaseStepW));
    }];
    UIImageView * dk_AuthBaseStepContactCenterImgView = [[UIImageView alloc] init];
    dk_AuthBaseStepContactCenterImgView.image = DK_GetImage(@"dk_AuthStepMiniNext");
    dk_AuthBaseStepContactCenterImgView.userInteractionEnabled = YES;
    [self addSubview:dk_AuthBaseStepContactCenterImgView];
    [dk_AuthBaseStepContactCenterImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_AuthBaseStepContact.mas_right).offset(DK_IsWidthScale(6));
        make.width.equalTo(@(DK_IsWidthScale(12)));
        make.height.equalTo(@(DK_IsWidthScale(12)));
        make.top.equalTo(dk_AuthBaseStepBasicCenterImgView);
    }];
    self.dk_AuthBaseStepBankCard = [[DKAuthBaseStepSubView alloc] init];
    self.dk_AuthBaseStepBankCard.authBaseStepType = AuthBaseStepTypeBankCard;
    [self addSubview:self.dk_AuthBaseStepBankCard];
    [self.dk_AuthBaseStepBankCard mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dk_AuthBaseStepContactCenterImgView.mas_right).offset(DK_IsWidthScale(6));
        make.bottom.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(self.dk_AuthBaseStepBasic);
        make.width.equalTo(@(AuthBaseStepW));
    }];
}
-(void)setDk_AuthStep:(NSString *)dk_AuthStep{
    _dk_AuthStep = dk_AuthStep;
    [self updateAwardAmount];
}
- (void)updateAwardAmount{
    WeakSelf(self)
    NSArray *awardAmountMdls = [DKGlobalHelper defaultManager].authAwardAmountMdls;
    if(awardAmountMdls.count > 0){
        [self makeShowAwardAmount];
    }else{
        [DKPublicHttp apiGetAwardAmountForAPI:@{} complete:^{
            [weakSelf makeShowAwardAmount];
        }];
    }
}
- (void)makeShowAwardAmount{
    if([self.dk_AuthStep isEqualToString:@"1"]){
        self.dk_AuthBaseStepBasic.authBaseStepAmount = [self getAwardAmountStep:@"LIVENESS_INFO"];
    }else if ([self.dk_AuthStep isEqualToString:@"2"]){
        NSString *LIVENESS_INFOStep = [self getAwardAmountStep:@"LIVENESS_INFO"];
        NSString *IDENTITY_INFOStep = [self getAwardAmountStep:@"IDENTITY_INFO"];
        self.dk_AuthBaseStepBasic.authBaseStepAmount = [NSString stringWithFormat:@"%d",[LIVENESS_INFOStep intValue]+[IDENTITY_INFOStep intValue]];
    }else{
        NSString *LIVENESS_INFOStep = [self getAwardAmountStep:@"LIVENESS_INFO"];
        NSString *IDENTITY_INFOStep = [self getAwardAmountStep:@"IDENTITY_INFO"];
        NSString *PERSONAL_INFOStep = [self getAwardAmountStep:@"PERSONAL_INFO"];
        self.dk_AuthBaseStepBasic.authBaseStepAmount = [NSString stringWithFormat:@"%d",[LIVENESS_INFOStep intValue]+[IDENTITY_INFOStep intValue]+[PERSONAL_INFOStep intValue]];
    }
    self.dk_AuthBaseStepContact.authBaseStepAmount = [self getAwardAmountStep:@"CONTACT_INFO"];
    self.dk_AuthBaseStepBankCard.authBaseStepAmount = [self getAwardAmountStep:@"BANK_INFO"];
    
    if([self.dk_AuthStep isEqualToString:@"1"]||[self.dk_AuthStep isEqualToString:@"2"]||[self.dk_AuthStep isEqualToString:@"3"]){
        self.dk_AuthBaseStepBasic.isCurrentSelect = YES;
        self.dk_AuthBaseStepContact.isCurrentSelect = NO;
        self.dk_AuthBaseStepBankCard.isCurrentSelect = NO;
    }else if([self.dk_AuthStep isEqualToString:@"4"]){
        self.dk_AuthBaseStepBasic.isCurrentSelect = YES;
        self.dk_AuthBaseStepContact.isCurrentSelect = YES;
        self.dk_AuthBaseStepBankCard.isCurrentSelect = NO;
    }else if([self.dk_AuthStep isEqualToString:@"5"]){
        self.dk_AuthBaseStepBasic.isCurrentSelect = YES;
        self.dk_AuthBaseStepContact.isCurrentSelect = YES;
        self.dk_AuthBaseStepBankCard.isCurrentSelect = YES;
    }
}
- (NSString *)getAwardAmountStep:(NSString *)step{
    if(step.length){
        NSArray *awardAmountMdls = [DKGlobalHelper defaultManager].authAwardAmountMdls;
        for (DKAuthAwardAmountModel *authAwardAmountMdl in awardAmountMdls) {
            if([authAwardAmountMdl.step isEqualToString:step]){
                return authAwardAmountMdl.amount;
            }
        }
    }
    return @"0";
}
@end
